/**
 * @description  : 待办文书中转页
 * @descriptionDetail : 待办文书中转页
 * @copyright    : 浙江烟草
 * @author       : mc
 * @create       : 2022-11-05 09:50:12
 */
<template>
  <view class="page">
  </view>
</template>

<script>
	import commonService from '@/service/common/common.service';
	import {
		COMMON_DOC,
		processDefKeyByInternalToZmDb,
	} from '@/service/enum/common-doc';
	export default {
		onLoad(op) {
			let opt = this.getRouteParam() || {};
			this.taskId = opt.taskId || op.taskId;
			this.procStatus = opt.procStatus;
			this.bizCode = opt.bizCode;
			this.bizUuid = opt.bizUuid;
			this.gfCode = opt.processDefKey;
			this.prevParam = opt;
		},
		data() {
			return {
				prevParam: {},
				taskId: '',
				bizCode: '',
				bizUuid: '',
				gfCode: '',
				procStatus: "", // 死亡或丧失行为能力书面告知书待办&已办区分字段
			};
		},
		mounted() {
			this.init();
		},
		methods: {
			init() {
				this.$modal.showLoading('加载中...');
				commonService
					.getBizTaskConfigBybizCode({
						taskId: this.taskId,
						bizCode: this.bizCode,
						bizUuid: this.bizUuid,
						sysCode: this.prevParam.sysCode,
						menuCode: '',
					})
					.then((res) => {
						this.$modal.hideLoading();
						if (res.success) {
							this.doIntent(res.bean);
						} else {
							this.$u.toast(res.msg);
							this.error();
						}
					})
					.catch((e) => {
						// 中转失败
						this.$modal.hideLoading();
						this.$modal.alert('待办打开失败', () => {
							this.error();
						});
					});
			},
			doIntent(obj) {
				if (obj.mobileFormUrl == 'pages/todo/commonDocPage') {
					// 如果存在gfcode 则表示是统一待办文书流程
					console.log(this.$u.test.object(COMMON_DOC[this.gfCode]), COMMON_DOC[this.gfCode], this.gfCode, 'gfcode');
					if (this.$u.test.object(COMMON_DOC[this.gfCode])) {
						this.setRouteParam({
							docInsUuid: this.bizUuid,
							gfCode: this.gfCode,
						});
						this.$u.route({
							url: '/pages/todo/commonDocPage',
							type: 'redirect',
						});
					} else {
						this.$modal.alert('该待办尚未在移动端支持,请在PC端处理', () => {
							this.error();
						});
					}
				} else if (obj.mobileFormUrl == 'pages/todo/docInternal') {
					if (processDefKeyByInternalToZmDb.indexOf(this.gfCode) != -1) {
						this.setRouteParam({
							docInsUuid: this.bizUuid,
							gfCode: this.gfCode,
						});
						this.$u.route({
							url: '/pages/todo/commonDocPage',
							type: 'redirect',
						});
					} else {
						this.$u.route({
							url: 'pages/todo/docInternal',
							params: {
								bizUuid: this.bizUuid,
							},
							type: 'redirect',
						});
					}
				} else if (obj.mobileFormUrl == 'pages/todo/storeDoc') {
					// 如果存在gfcode 则表示是统一待办文书流程
					if (this.$u.test.object(COMMON_DOC[this.gfCode])) {
						this.setRouteParam({
							taskId: this.taskId,
							bizUuid: this.bizUuid,
							gfCode: this.gfCode,
							bizCode: this.bizCode,
						});
						this.$u.route({
							url: '/pages/todo/storeDoc',
							type: 'redirect',
						});
					} else {
						this.$modal.alert('该待办尚未在移动端支持,请在PC端处理', () => {
							this.error();
						});
					}
				} else if (obj.mobileFormUrl == 'pages/threeMembersTeamWork/teamworkFlowTransfer') {
					/* 三员协同流程处理页面 ljb 20240508 start */
					this.setRouteParam({
						taskId: this.taskId,
						bizUuid: this.bizUuid,
						gfCode: this.gfCode,
						bizCode: this.bizCode,
					});
					this.$u.route({
						url: '/pages/threeMembersTeamWork/teamworkFlowTransfer',
						type: 'redirect',
					});
					/* 三员协同流程处理页面 ljb 20240508 end */
				} else if (obj.mobileFormUrl == 'pages/tripleNetworkIntegration/teamworkFlowTransfer') {
					/* 三网融合流程处理页面 ljb 20240523 start */
					this.setRouteParam({
						taskId: this.taskId,
						bizUuid: this.bizUuid,
						gfCode: this.gfCode,
						bizCode: this.bizCode,
					});
					this.$u.route({
						url: '/pages/tripleNetworkIntegration/teamworkFlowTransfer',
						type: 'redirect',
					});
					/* 三网融合流程处理页面 ljb 20240523 end */
				} else {
					// 用来表示是统一待办文书 则表示是自定义的流程 需要跳转到自定义页面去
					if (this.$u.test.isEmpty(obj.mobileFormUrl)) {
						this.$modal.alert('正在开发中...', () => {
							this.error();
						});
					} else {
						obj.taskId = this.taskId;
						obj.bizUuid = this.bizUuid;
						obj.gfCode = this.gfCode;
						obj.bizCode = this.bizCode;
						obj.bizCode = this.bizCode;
						// obj.processDefKey = this.prevParam.processDefKey;
						obj.procStatus = this.procStatus;
						this.setRouteParam(obj);
						this.$u.route({
							url: obj.mobileFormUrl,
							type: 'redirect',
						});
					}
				}
			},
			error() {
				uni.navigateBack();
			},
		},
	};
</script>

<style scoped lang="scss">
	.page {
		padding: 0;
		background-color: white;
	}
</style>